
package com.ukao.steward.pesenter.valetRunners;

import com.ukao.steward.base.BasePresenter;
import com.ukao.steward.bean.StringBean;
import com.ukao.steward.bean.WaitingOrderBean;
import com.ukao.steward.consts.Constant;
import com.ukao.steward.consts.SaveParams;
import com.ukao.steward.retrofit.ApiCallback;
import com.ukao.steward.view.valetRunners.DontTakeView;

import java.util.HashMap;

import rx.Observable;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class DontTakePesenter extends BasePresenter<DontTakeView> {


    public DontTakePesenter(DontTakeView view) {
        attachView(view);
    }

    /**
     取件员  送件，未取件
     */
    public void  requestReceiving(final   int pageNum ,int pageSize,int  type,String  storeId) {
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("pageNum",pageNum+"");
        mHashMap.put("pageSize",pageSize+"");
        mHashMap.put("storeId",storeId);
        mHashMap.put("accessToken", SaveParams.getToken());
        Observable  observable=null;
        switch (type) {
            case 1:/*未取*/
                observable =apiStores.waitTake(Constant.createParameter(mHashMap));
                break;
            case 2:/*未送*/
                observable =apiStores.waitSend(Constant.createParameter(mHashMap));
                break;
            case 3:/*完成*/
                observable =apiStores.complete(Constant.createParameter(mHashMap));
                break;

        }

        addSubscription(observable,
                new ApiCallback<WaitingOrderBean>() {
                    @Override
                    public void onSuccess(WaitingOrderBean model) {
                        if (model.getHttpCode() == 200) {
                            mvpView.receiveNoTakeSucceed(model.getData());
                        }else{
                            mvpView.showError(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {
                            mvpView.loadfinish();

                    }
                });


    }





    /**
     取件员   取件
     */
    public void receivingSend(final    WaitingOrderBean.ListBean   mListBean  ) {
        super.mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("orderId",mListBean.getId()+"");
        mHashMap.put("accessToken", SaveParams.getToken());
        addSubscription(super.apiStores.receivingSend(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode() == 200) {
                           mvpView.receivingSucceed(mListBean,model.getMsg());
                        }else{
                            mvpView.showError(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {

                        mvpView.hideLoading();

                    }
                });

    }

    /**
     取件员  签收
     */
    public void signParcel(final    WaitingOrderBean.ListBean   mListBean) {
        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("orderId",mListBean.getId()+"");
        mHashMap.put("accessToken", SaveParams.getToken());
        addSubscription(apiStores.signParcel(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.receivingSucceed(mListBean,model.getMsg());
                        }else{

                            mvpView.showError(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {

                        mvpView.hideLoading();

                    }
                });

    }

    /**
     * 送件员扫订单编号接收订单
     * @param orderNo
     */
    public void scancode(final   String  orderNo  ) {
        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("orderNo",orderNo);
        mHashMap.put("accessToken", SaveParams.getToken());
        addSubscription(apiStores.scancode(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode() == 200) {

                            mvpView.takeSuccerd();
                        }else{

                            mvpView.showError(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {

                        mvpView.hideLoading();

                    }
                });

    }


}
